<?php
abstract class Lesson
{
    private $duration;
    private $costStrategy;
    function __construct($duration, costStrategy $strategy)
    {
        $this->duration = $duration;
        $this->costStrategy = $strategy;
    }
    function cost()//委托
    {
        return $this->costStrategy->cost($this);
    }
    function chargeType()
    {
        return $this->costStrategy->chargeType();
    }
    function getDuration()
    {
        return $this->duration;
    }

}
class Lectrue extends Lesson
{
}
class Seminar extends Lesson
{
}
abstract class CostStrategy
{
    abstract function cost(Lesson $lesson);
    abstract function chargeType();
}
class TimedCostStrategy extends CostStrategy
{
    function cost(Lesson $lesson)
    {
        return ($lesson->getDuration() * 5);
    }
    function chargeType()
    {
        return "hourly rate";//该方法的扣费方式
    }
}
class FixedCostStrategy extends CostStrategy
{
    function cost(Lesson $lesson)
    {
        return 30;
    }
    function chargeType()
    {
        return "fixed rate";//该方法的扣费方式
    }
}
$lessons[] = new Seminar(4, new TimedCostStrategy());
$lessons[] = new Seminar(5, new FixedCostStrategy());
foreach ($lessons as $lesson) {
    print "lesson charge {$lesson->cost()}<br>";
    print "charge type： {$lesson->ChargeType()}<br>";
}
?>
